<?php

namespace App;

class GameArchive extends Model
{
    protected $table = 't_games_archive';

    /**
     * [gameType 判断游戏类型]
     * @return [type] [description]
     */
    public function gameType()
    {
    	$info = json_decode($this->base_info, true);
    	$game_name = '';
    	if ($info) {
    		switch ($info['type']) {
    			case 'kdd':
    				$game_name = '扣点点';
    				break;
    			case 'tdh':
    				$game_name = '推倒胡';
    				break;
    			case 'htwp':
    				$game_name = '洪洞王牌';
    				break;
    			case 'xzkdd':
    				$game_name = '忻州扣点';
    				break;
    			case 'jz':
    				$game_name = '晋中麻将';
    				break;
    		}
            $history = json_decode($this->history, true);
            if ($history) {
               $g_count = GameArchive::where(['room_uuid' => $this->room_uuid])->get()->count();
               $u_count = count($history['seats']);
               $game_name .= '('.$g_count.'回/'.$u_count.'人)';
            }
    	}
    	return $game_name;
    }

    /**
     * [gameUser 游戏玩家]
     * @return [type] [description]
     */
    public function gameUser()
    {
    	$history = json_decode($this->history, true);
    	$user = '';
    	if ($history['seats']) {
    		foreach ($history['seats'] as $key => $seat) {
    			if ($key % 2 != 0) {
    				$user .= '('.($key+1).') '.base64_decode($seat['name']).'<br/>';
    			} else {
    				$user .= '('.($key+1).') '.base64_decode($seat['name']) . ' <span style="color:red">|</span> ';
    			}
    			
    		}
    	}
    	return $user;
    }

}    